<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>PUML Assistant</title>
    <style>
        body {
            display: flex;
            flex-direction: column;
            align-items: center;
            font-family: Arial, sans-serif;
        }
        .container {
            display: flex;
            width: 80%;
            margin-top: 20px;
        }
        .input-area, .preview-area {
            flex: 1;
            margin: 10px;
        }
        textarea {
            width: 100%;
            height: 300px;
        }
        iframe {
            width: 100%;
            height: 300px;
            border: 1px solid #ccc;
        }
        /* 添加全屏预览的样式 */
        #fullscreenPreview {
            display: none; /* 初始隐藏 */
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background-color: rgba(0,0,0,0.8); /* 半透明背景 */
            justify-content: center;
            align-items: center;
            z-index: 1000;
        }
        #fullscreenPreview img {
            max-width: 90%;
            max-height: 90%;
        }
    </style>
</head>
<body>
    <h1>PUML Assistant</h1>
    <div class="container">
        <div class="input-area">
            <h2>Enter PUML Syntax</h2>
            <form id="pumlForm">
                <textarea id="diagram" name="diagram" required></textarea>
                <button type="submit">Generate</button>
            </form>
        </div>
        <div class="preview-area">
            <h2>Preview</h2>
            <iframe id="preview" src="about:blank"></iframe>
        </div>
    </div>
    <!-- 添加全屏预览容器 -->
    <div id="fullscreenPreview">
        <img src="#" alt="Full Screen Preview">
    </div>

    <script>
        document.getElementById('pumlForm').addEventListener('submit', function(event) {
            event.preventDefault();
            const diagram = document.getElementById('diagram').value;
            fetch(`/generate?diagram=${encodeURIComponent(diagram)}`)
                .then(response => response.text())
                .then(data => {
                    const previewFrame = document.getElementById('preview');
                    previewFrame.srcdoc = `<pre>${data}</pre>`;
                });
        });
        // 添加点击事件处理
        document.getElementById('preview').addEventListener('load', function() {
            const iframe = document.getElementById('preview');
            const fullscreenDiv = document.getElementById('fullscreenPreview');
            // 等待iframe内容加载完成
            iframe.contentDocument.body.onclick = function() {
                const img = iframe.contentDocument.body.querySelector('img');
                if (img) {
                    fullscreenDiv.querySelector('img').src = img.src;
                    fullscreenDiv.style.display = 'flex';
                }
            };
        });
        // 点击全屏预览时退出全屏
        document.getElementById('fullscreenPreview').onclick = function() {
            this.style.display = 'none';
        };
    </script>
</body>
</html>
